package com.gem.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import org.apache.log4j.Logger;

import com.gem.dao.UBuyBookDAO;
import com.gem.pojo.UBuyInfo;
import com.gem.util.DBHelper;

public class UBuyBookDAOImpl implements UBuyBookDAO {
	private static Logger log=Logger.getLogger(UBuyBookDAOImpl.class.getName());
	Connection conn=null;
	PreparedStatement psta=null;
	ResultSet res=null;
	@Override
	public List<String[]> getBuyerInfo(String uid) {
		// TODO Auto-generated method stub
		conn=DBHelper.getConnection();
		List<String[]> list=new ArrayList<String[]>();
		String str[]=null;
		try{
			String sql="select buybookid,bname,bprice,buybooknum,buydate,bprice*buybooknum as total from ubuyinfo inner join books  on books.bid=ubuyinfo.buybookid where ubuyinfo.uid =?";
			psta=conn.prepareStatement(sql);
			psta.setString(1, uid);
			res=psta.executeQuery();
			while(res.next()){
				str=new String[7];
				str[1]=res.getString(1);
				str[2]=res.getString(2);
				str[3]=String.valueOf(res.getDouble(3));
				str[4]=String.valueOf(res.getInt(4));
				str[5]=String.valueOf(res.getDate(5));
				str[6]=String.valueOf(res.getDouble(6));
				list.add(str);
			}
			
		}catch(SQLException ex){
			System.out.println("aaaa");
			log.error(ex);
		}finally{
			DBHelper.closeAll(conn, psta, res);
		}
		return list;
	}

	@Override
	public List<String[]> getBuyerUsedMoney() {
		// TODO Auto-generated method stub
//		select uid,sum(bprice*buybooknum) as total
//		from ubuyinfo inner join books  on books.bid=ubuyinfo.buybookid
//		group by uid
//		order by total asc
		return null;
	}

	@Override
	public double getAssets() {
		// TODO Auto-generated method stub
		return 0;
	}

}
